#ifndef _CYUV_H_
#define _CYUV_H_
#include <iostream>
using namespace std;
class ColorRGB{
public:
	int r,g,b;
public:
	ColorRGB()
	{
		r=0;
		g=0;
		b=0;
	}
	ColorRGB(int a,int b,int c) 
	{ 
		this->r = a;
		this->g = b;
		this->b = c; 
	}

	void RGBtoYUV(ColorRGB c,int& _y,int& _u,int& _v)
	{
		double y, u, v;
		y = 0.299 * c.r + 0.587 * c.g + 0.114 * c.b;
		u = 0.492 * (c.b - y) + 128;
		v = 0.877 * (c.r - y) + 128;
		y = y < 255 ? y :255;
		u = u < 255 ? u : 255;
		v = v < 255 ? v : 255;
		y = y < 0 ?0: y ;
		u = u < 0 ?0: u;
		v = v < 0 ?0: v;
		_y = static_cast<int>(y);
		_u = static_cast<int>(u);
		_v = static_cast<int>(v);
	}
};


class ColorYUV
{
public:
	int y,u,v;
public:
	ColorYUV()
	{
		this->y=0;
		this->u=0;
		this->v=0;
	}
	ColorYUV(int a,int b,int c) 
	{ 
		this->y = a;
		this->u = b;
		this->v = c; 
	}
	// 	R = Y + 1.14V 
	// 	G = Y - 0.39U - 0.58V 
	// 	B = Y + 2.03U
	void YUVtoRGB(ColorYUV& c,int& r,int& g,int& b)
	{
		double _r;
		double _g;
		double _b;
 		_r = c.y + 1.140 * (c.v - 128);
 		_g = c.y - 0.394 * (c.u - 128) - 0.581 * (c.v - 128);
 		_b = c.y + 2.032 * (c.u - 128);


// 		_r = c.y + 1.140 * c.v;
// 		_g = c.y - 0.394 * c.u - 0.581 * c.v;
// 		_b = c.y + 2.032 * c.u;

		_r=_r<255?_r:255;
		_g=_g<255?_g:255;
		_b=_b<255?_b:255;
		_r = _r < 0 ? 0 : _r;
		_g = _g < 0 ? 0 : _g;
		_b = _b < 0 ? 0 : _b;
		r = static_cast<int>(_r);
		g = static_cast<int>(_g);
		b = static_cast<int>(_b);
		cout<<r<<" "<<g<<" "<<b<<endl;
	}
};

#endif